package com.assessment.servermanager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.assessment.servermanager.commen.controller.BaseController;
import com.assessment.servermanager.commen.entity.AjaxResult;
import com.assessment.servermanager.commen.entity.PageQuery;
import com.assessment.servermanager.commen.page.TableDataInfo;
import com.assessment.servermanager.entity.TbApprove;
import com.assessment.servermanager.entity.bo.TbApproveBo;
import com.assessment.servermanager.entity.vo.TbApproveVo;
import com.assessment.servermanager.service.ITbApproveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 【请填写功能名称】Controller
 *
 * @author jiajia
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/approve")
public class TbApproveController extends BaseController {
    @Autowired
    private ITbApproveService tbApproveService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo<TbApproveVo> list(TbApproveBo tbApproveBo, PageQuery pageQuery) {
        return tbApproveService.selectTbApproveList(tbApproveBo,pageQuery);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbApprove tbApprove) {
        /*List<TbApprove> list = tbApproveService.selectTbApproveList(tbApprove);
        ExcelUtil<TbApprove> util = new ExcelUtil<TbApprove>(TbApprove.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");*/
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbApproveService.selectTbApproveById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PostMapping
    public AjaxResult add(@RequestBody TbApprove tbApprove) {
        return toAjax(tbApproveService.insertTbApprove(tbApprove));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TbApprove tbApprove) {
        return toAjax(tbApproveService.updateTbApprove(tbApprove));
    }

    /**
     * 删除【请填写功能名称】
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbApproveService.deleteTbApproveByIds(ids));
    }

    /**
     * 审批
     * @param id  申请记录ID
     * @param state 审批结果
     */
    @PostMapping("/examine/{id}/{state}")
    public AjaxResult examine(@PathVariable Long id,@PathVariable Integer state){
        TbApprove approve = new TbApprove();
        approve.setId(id);
        approve.setState(state);
        return toAjax(tbApproveService.updateTbApprove(approve));
    }

}
